package com.water.camera.mark;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.water.camera.bean.EditItem;
import com.water.camera.databinding.LayoutWatermark67Binding;

import java.text.SimpleDateFormat;
import java.util.ArrayList;

public class Mark67 extends BaseMark {

    LayoutWatermark67Binding binding;

    public Mark67(@NonNull Context context) {
        super(context);
    }

    public Mark67(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public Mark67(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void init(int type) {
        if (type == 0) {
            binding = LayoutWatermark67Binding.inflate(LayoutInflater.from(getContext()));
            addView(binding.getRoot());
            hideView(binding.binding10);
        } else {
            binding = LayoutWatermark67Binding.inflate(LayoutInflater.from(getContext()), this, true);
        }
        update();
    }

    private void setTime() {
        long time = getTime();
        if (time > 0) {
            String str = new SimpleDateFormat("HH:mm").format(time);
            String[] ss = str.split(":");
            int i = Integer.valueOf(ss[0]);
            if (i < 8) {
                binding.binding3.setText("早晨");
            } else if (i < 11) {
                binding.binding3.setText("上午");
            } else if (i < 14) {
                binding.binding3.setText("中午");
            } else if (i < 19) {
                binding.binding3.setText("下午");
            } else {
                binding.binding3.setText("晚上");
            }
            binding.binding4.setText(str);
            str = new SimpleDateFormat("yyyy.MM.dd").format(time);
            binding.binding5.setText(str);
            setWeek(binding.binding6);
        }
    }

    @Override
    public void update() {
        setText(binding.binding1, "title67");
        setText(binding.binding3, "time67", binding.binding2);
        setTime();
        setText(binding.binding7, "weather67", binding.binding7);
        setText(binding.binding8, "desc67", binding.binding8);
        setText(binding.binding9, "beizhu67", binding.more);

        setText(binding.binding11, "didian67", binding.binding10);

        super.update();
    }

    @Override
    public ArrayList<EditItem> getEditItems() {
        ArrayList<EditItem> list = new ArrayList<>();
        list.add(new EditItem("title67", "标题"));
        list.add(new EditItem("time67", "时间", true));
        list.add(new EditItem("weather67", "天气"));
        list.add(new EditItem("desc67", "描述"));
        list.add(new EditItem("beizhu67", "备注"));
        list.add(new EditItem("didian67", "地点"));

        return list;
    }

    @Override
    public void onValueChange(EditItem item) {
        if (item.isTime) {
            setTime();
        } else {
            super.onValueChange(item);
        }
    }

    @Override
    public void onShowChange(EditItem item) {
        if (item.isTime) {
            if (item.show) {
                showView(binding.binding2, binding.binding5, binding.binding6);
            } else {
                hideView(binding.binding2, binding.binding5, binding.binding6);
            }
        } else {
            super.onShowChange(item);
        }
    }
}
